package aa;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.UnsupportedEncodingException;
import java.util.concurrent.locks.ReentrantLock;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.DefaultHttpClient;

public class test {

	public static void main(String[] args) throws Exception {
		
//		String url="http://49.64.195.105:8080/studio/testpic";
//		HttpClient client = new DefaultHttpClient();
//		HttpPost httpPost = new HttpPost(url);
//		 StringEntity se = new StringEntity(loadFile());
//		 httpPost.setEntity(se);
//		 client.execute(httpPost);
		
//		Pic2String ps=new Pic2String("C:/Users/PC/Desktop/qq.jpg");
//		String2Pic sp=new String2Pic(ps.pic2Str());
//		sp.savePic();
		
		
		
		String url="http://49.64.195.105:8080/studio/testpic";
		 HttpClient httpClient = new DefaultHttpClient();
		 HttpPost httpPost = new HttpPost(url);
		 File f = new File("C:/Users/PC/Desktop/qq.jpg");
         FileBody fo = null;
         MultipartEntityBuilder reqEntity =MultipartEntityBuilder.create();
         reqEntity.addBinaryBody("img", f);
         httpPost.setEntity( reqEntity.build());
         httpClient.execute(httpPost);
         
         
		 

	}
	
//	public static String loadFile(){
//		String 	filePath="C:/Users/PC/Desktop/qq.jpg";
//		File  file = new File(filePath);
//
//        FileInputStream fis = null;
//        ByteArrayOutputStream in = null;
//        byte[] data = null ;
//
//        try {
//            fis = new FileInputStream(file);
//            in = new ByteArrayOutputStream((int) file.length());
//
//            byte[] buffer = new byte[1024];
//            int len = -1;
//            while ((len = fis.read(buffer)) != -1) {
//                in.write(buffer, 0, len);
//            }
//
//            data = in.toByteArray() ;
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            try {
//                if (fis != null) {
//                    fis.close();
//                    fis = null;
//                }
//
//                in.close();
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
//        
//        return new String(data,0,data.length);
//    }
}
